<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./resrt.css">
    <style>
        #ele{
            width: 300px;
            margin: 100px auto;
            border: 3px solid rgb(241, 117, 60);
            padding: 10px;
        }
        .top{
            height: 50px;
            line-height: 50px;
        }
        .top input{
            height: 30px;
            border: 1px solid #eee;
            border-radius: 5px;
            width: 80%;
            padding-left: 10px;
            box-sizing: border-box;
        }
        .top button{
            height: 30px;
            width: 17%;
        }
        .bottom{
            box-sizing: border-box;
            padding: 10px;
        }
        .list{
            height: 50px;
            line-height: 50px;
            display: flex;
            justify-content: space-between;
            background-color: rgb(231, 81, 81);
            margin-top: 20px;
        }
        .list p{
            width: 70%;
            text-align: center;
        }
        .list button {
            width: 20%;
        }
        .change{
            background-color: cornflowerblue;
        }

    </style>
</head>
<body>
    <div id="ele">
        <div class="top">
            <input type="text" placeholder="请输入添加的任务" v-model="from.text">
            <button @click="add">添加</button>
        </div>
        <div class="bottom">
            <div :class="`list ${item.state ? 'change' : ''} `" v-for="(item , index) in list" :key="index">
                <input type="checkbox" @click="change(item)">
                <p>{{item.text}}</p>
                <button @click="remove(index)">删除</button>
            </div>
        </div>
    </div>
</body>
</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var num = 0
    var v = new Vue({
        el:'#ele',
        data:{
            from:{text:''},
            list:[]
        },
        methods:{
            add(){
                num++
                var obj 
                this.from.text ? obj = {id: num , state : false , text:this.from.text} : null
                this.from.text ? this.list.push(obj) : null
                this.from.text = ''
            },
            change(item){
                item.state = !item.state
            },
            remove(index){
                this.list.splice(index , 1)
                console.log(this.list);
            }
        }
    })
</script>